<style type="text/css">
.sizetable th,.sizetable td{padding:3px 5px !important;text-align:center;}
.layui-table td, .layui-table th {padding:6px 9px;}
</style>
    <div>
    
    	{if $action != 'checkoutManage' }
        	{if $action == 'fabricsCheckouts' }<!--面料出库页 -->
                <form  class="layui-form layui-form-pane fixed-bar-form" action="" method="post" id="hisi-table-search">
                   <div>
                   {if($isButton!=1) }
                        <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                            <thead>
                                <tr>
                                  <th>物料属性</th>
                                    <th>物料名称</th>
                                    <th>颜色</th>
                                    <th>余料工厂</th>
                                    <th>货仓/货架</th>
                                    <th>采购批号</th>
                                    <th>物料id</th>
                                     <th>总库存数</th>
                                    <th>占用出库数量</th>

                                    <th>使用订单号</th>
                                    <th width="130">订单工厂</th>
                                </tr>
                            </thead>
                            <tbody class="edit_process_body">
                                {foreach $datalist as $k => $v}
                                <tr>
                                  <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                                      <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br /><span class='copy-item'>{$v['minfo']['material_sku']}</span>
                                      <br /><span class='copy-item'>{$v['minfo']['self_sku']}</span></td>
                                      <td>{$v['minfo']['color']}</td>
                                      <td>{$factoryKV[$v['factory_id']]}</td>
                                      <td>{$v.storehouse_name}<br>{$v.storeshelf_name}</td>
                                      <td>{$v['caigou_number']}</td>
                                      <td>{$v['cloth_num']}</td>
                                      <td>{$v.stockall} {$v.unit}</td>
                                      <td><strong>{$v.use_num}</strong> {$v.unit}
                                      <input type="hidden" name="stock_action[]" value="{$v.action_id}">
                                      <input type="hidden" name="material_id[]" value="{$v.material_id}">
                                        <input type="hidden" name="out_stock[]" value="{$v.apply_used}">                                  </td>

                                      <td>{$v.client_ordernum}</td>
                                  <td><label>
                                    <select name="in_factory[]" lay-ignore>
                                    {foreach $factoryKV as $k=>$fname}
                                    <option value="{$k}"  {if $v['select_factory_id'] == $k && $v['select_factory_id']>0}selected='selected'{/if}>{$fname}</option>
                                    {/foreach}
                                    </select>
                                  </label></td>
                                </tr>
                                {/foreach}
                            </tbody>
                        </table>
                    {else /}
                     <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                            <thead>
                                <tr>
                                  <th>选择出库</th>
                                  <th>物料属性</th>
                                    <th>物料名称</th>
                                    <th>颜色</th>
                                    <th>余料工厂</th>
                                    <th>货仓/货架</th>
                                    <th>采购批号</th>
                                    <th>物料id</th>
                                     <th>总库存数</th>
                                    <th>占用出库数量</th>

                                    <th>使用订单号</th>
                                    <th width="130">订单工厂</th>
                                    <th>申请人</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody class="edit_process_body">
                                {foreach $datalist as $k => $v}
                                <tr>
                                  <td>
                                      <input type="checkbox" name="out_stockid[]" class="out_stockid" lay-skin="primary" value="{$v['id']}" /></td>
                                  <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                                      <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br /><span class='copy-item'>{$v['minfo']['material_sku']}</span>
                                      <br /><span class='copy-item'>{$v['minfo']['self_sku']}</span></td>
                                      <td>{$v['minfo']['color']}</td>
                                      <td>{$factoryKV[$v['factory_id']]}</td>
                                      <td>{$v.storehouse_name}<br>{$v.storeshelf_name}</td>
                                      <td>{$v['caigou_number']}</td>
                                      <td>{$v['cloth_num']}</td>
                                      <td>{$v.stockall} {$v.unit}</td>
                                      <td><strong>{$v.use_num}</strong> {$v.unit}
                                      <input type="hidden" name="stock_action[]" value="{$v.action_id}">
                                      <input type="hidden" name="material_id[]" value="{$v.material_id}">
                                        <input type="hidden" name="out_stock[]" value="{$v.apply_used}">                                  </td>

                                      <td><input type="text" name="client_ordernum[]" value="{$v.client_ordernum}" style="width:80px;height:32px;border:1px solid #D2D2D2;padding-left:3px;">   </td>
                                  <td><label>
                                    <select name="in_factory[]" lay-ignore>
                                    {foreach $factoryKV as $k=>$fname}
                                    <option value="{$k}"  {if $v['select_factory_id'] == $k && $v['select_factory_id']>0}selected='selected'{/if}>{$fname}</option>
                                    {/foreach}
                                    </select>
                                  </label></td>
                                  <td>{$v['apply_user']}</td>
                                  <td><a data-href="{:url('materialStock/cancel')}?material_id={$v.material_id}&client_ordernum={$v.client_ordernum}&material_stock_id={$v.id}" class=" layui-btn layui-btn-xs layui-btn-danger j-tr-del">撤消占用</a></td>
                                </tr>
                                {/foreach}
                            </tbody>
                        </table>
                    {/if}
                    <div class="pop-bottom-bar">
                        {if($isButton==1) }
                        	<button type="submit" class="layui-btn layui-btn-primary"  btn_name="edit_one" lay-submit="" action_state='60' lay-filter="demo1">打印出库标签</button>
                            <button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" action_state='110' lay-filter="demo1">确认出库</button>
                        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
                        {/if}
                    </div>
                   </div>
                </form>
            {else /}<!--批量出库待提交 -->
                <form  class="layui-form layui-form-pane fixed-bar-form" action="" method="post" id="hisi-table-search">
                   <div>
                        <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                            <thead>
                                <tr>
                                  <th>物料属性</th>
                                    <th>物料名称</th>
                                    <th>颜色</th>
                                   <!-- <th>工厂</th>-->
                                    <th>货仓/货架</th>
                                    <th>采购批号</th>
                                    <th>物料id</th>
                                    <th>总库存数</th>
                                    <th>选择发货</th>
                                    <th>出库数量</th>
                                    <th>使用订单号</th>
                                    <th width="130">选择目标工厂</th>
                                </tr>
                            </thead>
                            <tbody class="edit_process_body">
                                {foreach $datalist as $k => $v}
                                <tr>
                                  <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                                      <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br /><span class='copy-item'>{$v['minfo']['material_sku']}</span>
                                      <br /><span class='copy-item'>{$v['minfo']['self_sku']}</span></td>
                                      <td>{$v['minfo']['color']}</td>
                                      <!--<td>{$factoryKV[$v['factory_id']]}</td>-->
                                      <td>{$v.storehouse_name}<br>{$v.storeshelf_name}</td>
                                      <td>{$v['caigou_number']}</td>
                                      <td>{$v['cloth_num']}</td>
                                      <td>{$v.stock} {$v.unit}
                                      <input type="hidden" name="material_id[]" value="{$v.material_id}"></td>
                                      <td>
                                      <input type="checkbox" name="out_stockid[]" lay-skin="primary" value="{$v['id']}" /></td>
                                      <td><input type="text" name="out_stock[]" value="{$v.stock}" style="width:70px;height:32px;border:1px solid #D2D2D2;padding-left:3px;"> </td>
                                      <td><input type="text" name="client_ordernum[]" value="" style="width:80px;height:32px;border:1px solid #D2D2D2;padding-left:3px;">   </td>
                                  <td><label>
                                    <select name="in_factory[]" lay-ignore>
                                    {foreach $factoryKV as $k=>$v}
                                    <option value="{$k}">{$v}</option>
                                    {/foreach}
                                    </select>
                                  </label></td>
                                </tr>
                                {/foreach}
                            </tbody>
                        </table>
                     <div class="pop-bottom-bar">
                            <button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" action_state='101' lay-filter="demo1">确认发货</button>
                            &nbsp;<button type="submit" class="layui-btn layui-bg-orange"  btn_name="edit_one" lay-submit="" action_state='100' lay-filter="demo1">出库提交</button>&nbsp;

                        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
                    </div>
                   </div>
                </form>
            {/if}
        {else /}<!--批量出库已提交 -->
            <form  class="layui-form layui-form-pane fixed-bar-form" action="" method="post" id="hisi-table-search">
           <div>
           		{if($isButton==1) }
                    <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                    <thead>
                        <tr>
                          <th>物料属性</th>
                            <th>物料名称</th>
                            <th>颜色</th>
                            <th>工厂</th>
                            <th>货仓/货架</th>
                            <th>采购批号</th>
                            <th>物料id</th>
                            <th>总库存数</th>
                            <th>选择发货</th>
                            <th><strong>出库数量</strong></th>
                            <th>使用订单号</th>
                            <th width="130">选择目标工厂</th>
                        </tr>
                    </thead>
                    <tbody class="edit_process_body">
                        {foreach $datalist as $k => $v}
                        <tr>
                          <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                              <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br /><span class='copy-item'>{$v['minfo']['material_sku']}</span>
                              <br /><span class='copy-item'>{$v['minfo']['self_sku']}</span></td>
                              <td>{$v['minfo']['color']}</td>
                              <td>{$factoryKV[$v['factory_id']]}</td>
                              <td>{$v.storehouse_name}<br>{$v.storeshelf_name}</td>
                              <td>{$v['caigou_number']}</td>
                              <td>{$v['cloth_num']}</td>
                              <td>{$v.stockall} {$v.unit}  
                              <input type="hidden" name="stock_action[]" value="{$v.action_id}">
                              <input type="hidden" name="material_id[]" value="{$v.material_id}"></td>
                              <td>
                              <input type="checkbox" name="out_stockid[]" lay-skin="primary" value="{$v['id']}" /></td>
                              <td><input type="text" name="out_stock[]" value="{$v.apply_used}" style="width:70px;height:32px;border:1px solid #D2D2D2;padding-left:3px;font-weight:bold;" />
                              </td>
                              <td><input type="text" name="client_ordernum[]" value="{$v.client_ordernum}" style="width:80px;height:32px;border:1px solid #D2D2D2;padding-left:3px;">   </td>
                          <td><label>
                            <select name="in_factory[]" lay-ignore>
                            {foreach $factoryKV as $k=>$fname}
                            <option value="{$k}"  {if $v['select_factory_id'] == $k && $v['select_factory_id']>0}selected='selected'{/if}>{$fname}</option>
                            {/foreach}
                            </select>
                          </label></td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
             {else /}
                    <table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                    <thead>
                        <tr>
                          <th>物料属性</th>
                            <th>物料名称</th>
                            <th>颜色</th>
                            <th>工厂</th>
                            <th>货仓/货架</th>
                            <th>采购批号</th>
                            <th>物料id</th>
                            <th>出库数量</th>
                          <th>使用订单号</th>
                            <th width="160">选择目标工厂</th>
                        </tr>
                    </thead>
                    <tbody class="edit_process_body">
                        {foreach $datalist as $k => $v}
                        <tr>
                          <td style="padding:3px 10px;">{$stock_m_type[$v['stock_m_type']]}</td>
                              <td>{:htmlspecialchars_decode($v['minfo']['mtype'])} {$v['minfo']['name']}<br /><span class='copy-item'>{$v['minfo']['material_sku']}</span>
                              <br /><span class='copy-item'>{$v['minfo']['self_sku']}</span></td>
                              <td>{$v['minfo']['color']}</td>
                              <td>{$factoryKV[$v['factory_id']]}</td>
                              <td>{$v.storehouse_name}<br>{$v.storeshelf_name}</td>
                              <td>{$v['caigou_number']}</td>
                              <td>{$v['cloth_num']}</td>
                              <td>{$v.use_num} {$v.unit}  
                              <input type="hidden" name="stock_action[]" value="{$v.action_id}">
                              <input type="hidden" name="material_id[]" value="{$v.material_id}">
                                <input type="hidden" name="out_stock[]" value="{$v.apply_used}">
                              </td>
                              <td>{$v.client_ordernum}</td>
                          <td><label>
                            <select name="in_factory[]" lay-ignore>
                            {foreach $factoryKV as $k=>$fname}
                            <option value="{$k}"  {if $v['select_factory_id'] == $k && $v['select_factory_id']>0}selected='selected'{/if}>{$fname}</option>
                            {/foreach}
                            </select>
                          </label></td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
				{/if}
    		<div class="pop-bottom-bar">
                {if($isButton==1) }
                    <button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" action_state='101' lay-filter="demo1">确认发货</button>
                <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
                {/if}
            </div>
           </div>
            </form>
        
        {/if}
    </div>
<div style="display:none">
<table id="dataTable"></table>
</div>

{include file="system@block/layui" /}
<script>
	layui.use(['tool','laydate','table','form'], function() {
		var element = layui.element;
		var layer = layui.layer;
		var $ = layui.jquery;
		var form = layui.form;
		var table = layui.table;
		table.render({
            elem: '#dataTable'
            ,url: "{:url('')}" //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: false
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                 {field: 'create_time', title: '操作时间',templet: '#createTimeTpl', width:160}
                ,{field: 'stall_cost_type', title: '费用单类型'}
                ,{field: 'stall_cost_money', title: '费用单金额'}
                ,{field: 'pic', title: '图片',templet:'#picTpl'}
                ,{field: 'remark', title: '备注'}
                
            ]]
        });
		function doSaveStock(data){
			var uploadtoJinp=data['action_state'];
			$.ajax({
			   type: "POST",
			   url: "{:url('mp/stockNew/detailCheckouts')}?action=dosave",
			   data: data,
			   dataType:"json",
			   success: function(res){
					var data=res.data;
					if(res.code==1){
					    if(uploadtoJinp==60){
                            window.open(res.data.url);return;
                        }
						successMsg='数据提交成功'
						if(uploadtoJinp==1){
							//successMsg+='，'+data['msg'];
						}
						setTimeout(function(){
							parent.layui.layer.closeAll();
							if(isExitsFunction(parent.reloadTable)){
								parent.reloadTable();
							}
							if(isExitsFunction(parent.statCli)){
								parent.statCli(2);
							}
							
						},1200);
						layer.msg(successMsg, {icon: 1,anim: 6});
						return;

					}else{
                        layer.msg(res.msg, {icon: 2,anim: 6});
						$("#action_result").html(res.msg);
					}

			   }
			});
		}
		function isExitsFunction(funcName) { try { if (typeof (eval(funcName)) == "function") { return true; } } catch (e) { } return false; }
		
        form.on('submit(demo1)', function (data) {
            //表单数据formData
            var uploadtoJinp=$(this).attr("action_state");
			var formData;
            formData = data.field;
			formData['action_state'] = uploadtoJinp;
            doSaveStock(formData)
			return ;
        })
		
		// 监听物料切换，显示mes幅宽
		window.removePrice = function(e) {
			var tr=$(e).parent().parent();
			$(e).parent().parent().remove();

			//$(".edit_process_body").remove()
		}
	});
</script>